package com.starwish.starwishblog.web.front;

import com.starwish.starwishblog.entity.Board;
import com.starwish.starwishblog.result.ResultResponse;
import com.starwish.starwishblog.service.BoardService;
import com.starwish.starwishblog.vo.BoardVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("board")
public class FBoardController {

    @Autowired
    BoardService boardService;

    @GetMapping("/getBoardAndCategory")
    public ResultResponse<List<BoardVo>> getBoardAndCategory(){
        ResultResponse<List<BoardVo>> result = null;
        try {
            List<BoardVo> boardAndCate = boardService.findBoardAndCategory();
            result = new ResultResponse<>(200,"查询板块和类别成功",boardAndCate);
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(305,"查询板块和类别失败");
        }
        return result;
    }

    @GetMapping("/getBoardNameByCateId")
    public ResultResponse<String> getBoardNameByCateId(@RequestParam("categoryId") Integer categoryId){
        ResultResponse<String> result = null;

        try {
            String name = boardService.findBoardNameByCateId(categoryId);
            result = new ResultResponse<>(200,"根据类别id查板块名成功",name);
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(305,"根据类别id查板块名失败");
        }
        return result;
    }
}
